import VerEx from 'verbal-expressions';

/**
 * 标签名称
 * @type {string}
 */
const TNAME = `[a-zA-Z][\\w\\-\\.]*`;

export const REGEX_TAG_NAME = VerEx()
    .beginCapture()
    .then(/[a-zA-Z][a-zA-Z0-9\-\.\_]*/g)
    .endCapture()
    .toRegExp();

/**
 * 开始标签打开
 * @type {string}
 */
export const REGEX_TAG_OPEN = VerEx()
    .startOfLine()
    .then(/\s*/g)
    .then('<')
    .then(REGEX_TAG_NAME)
    .toRegExp();

/**
 * 开始标签结束
 * @type {string}
 */
export const REGEX_TAG_CLOSE = VerEx()
    .startOfLine()
    .then(/\s*/g)
    .maybe('/')
    .then('>').toRegExp();

/**
 * 结束标签
 * @type {string}
 */
export const REGEX_TAG_END = VerEx()
    .startOfLine()
    .then(/\s*/g)
    .then('</')
    .beginCapture()
    .then(REGEX_TAG_NAME)
    .then('>')
    .endCapture()
    .toRegExp();

/**
 * 标签属性
 * @type {string}
 */
export const REGEX_TAG_ATTR = VerEx()
    .startOfLine()
    .then(/\s*/g)
    .beginCapture()
    .maybe(
        VerEx()
            .maybe("@")
            .maybe(":")
            .toRegExp()
    )
    .then(/[a-zA-Z][a-zA-Z0-9\.\-]+/g)
    .endCapture()
    .maybe(
        VerEx()
            .then('=')
            .then('"')
            .beginCapture()
            .anythingBut('"')
            .endCapture()
            .then('"').toRegExp()
    ).toRegExp();
/**
 * 标签属性
 * @type {string}
 */
export const REGEX_TAG_TEXT = VerEx()
    .startOfLine()
    .then(/\s*/g)
    .beginCapture()
    .somethingBut(/<[a-zA-Z]/g)
    .endCapture()
    .toRegExp();

/**
 * 闭包开始
 * @type {string}
 */
export const REGEX_CLOSURE_START = /^{$/g;

/**
 * 闭包结束
 * @type {string}
 */
export const REGEX_CLOSURE_END = /^}$/g;

/**
 * 语句
 * @type {string}
 */
export const REGEX_STATEMENT = /[0-9a-zA-Z]/g;